package com.jt.resource.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 金帮嘉诚 @date 2021-08-19 星期四 10:40
 */
/*在修改配置文件时 类的属性不会重新初始化 因此logLevel不会被改变
如果想要使其随着配置文件改变而重新获取 就要使用该注解*/
@RefreshScope//在修改配置文件时 重新初始化属性(通过 重新创建 类的对象 的方式)
@RestController
@RequestMapping("/provider")
public class ProviderController {
    private Logger log = LoggerFactory.getLogger(ProviderController.class);

    @Value("${logging.level.com.jt:error}")
    private String logLevel;

    @GetMapping("/getLogLevel")
    public String doGetlogLevelllll() {
        log.trace("===trace===");
        log.debug("===debug===");
        log.info("===info===");
        log.warn("===warn===");
        log.error("===error===");
        return "log level is " + logLevel;
    }

    @Value("${server.tomcat.thread.max:200}")
    private String maxThread;

    @GetMapping("/getMaxThread")
    public String doGetMaxThread(){
        return "线程池最大数量: "+maxThread;
    }

    @Value("${page.pageSize:10}")
    private String pageSize;

    @GetMapping("/getPageSize")
    public String doGetPageSize(){
        return "每页条数: "+pageSize;
    }
}
